import { SuperMap3D } from '@/utils/supermap3d';

/**
 * 飞行动画
 * @param {*} viewer 场景
 * @param {Array} location 经、纬度、高度
 * @param {*} orientation 旋转角度
 * @param {*} duration 飞行时间
 */
export const flyTo = ({
  viewer,
  location,
  orientation = {
    heading: SuperMap3D.Math.toRadians(0),
    pitch: SuperMap3D.Math.toRadians(-90),
    roll: 0.0,
  },
  duration = 3,
}) => {
  viewer.camera.flyTo({
    destination: new SuperMap3D.Cartesian3.fromDegrees(...location),
    orientation,
    duration,
  });
};

/**
 * 昼夜切换
 */
export const dayNightChange = (viewer) => {
  // const dayLayers = viewer.imageryLayers;
  // const nightLayer = dayLayers.get(0);
  // const dayLayer = dayLayers.get(1);

  viewer.scene.globe.enableLighting = true;
  //确定调用Clock#tick时前进的时间，负值允许向后前进。
  viewer.clock.multiplier = 5000;
  // nightLayer.dayAlpha = 0.0;
};

/**
 * 环境设置
 */
export default class Environment {
  viewer: any;
  constructor(viewer) {
    this.viewer = viewer;
  }
  openShadow() {
    //恢复照明的距离。启用以太阳为光源照亮地球
    this.viewer.scene.globe.enableLighting = true;
    //是否启用阴影贴图。
    this.viewer.scene.shadowMap.enabled = true;
  }
  reset() {
    this.viewer.scene.globe.enableLighting = false;
    this.viewer.scene.shadowMap.enabled = false;
  }
}

/***
 * 时间控制器
 */
export class TimeClock {
  viewer: any;
  options: any; // 或者更具体的类型
  constructor(viewer: any, options: any) {
    this.viewer = viewer;
    this.options = options;
    this.init();
  }
  init() {
    this.viewer.scene.globe.enableLighting = true;
  }
  setTime(time = '2025-06-10 08:00:00') {
    const date = new Date(time);
    // 转为世界时
    const JulianDate = SuperMap3D.JulianDate.fromDate(date);
    // 比北京时间晚8小时，北京时间=JulianDate+8
    this.viewer.clock.currentTime = SuperMap3D.JulianDate.addHours(JulianDate, 8, new SuperMap3D.JulianDate());
  }
  /**
   * 允许阴影
   */
  enableShadow() {
    this.viewer.scene.shadows = true;
  }
}
